﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBBase;
using System.Threading;
using System.Xml;
using System.Web;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
using System.IO;
using CCWin;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using System.Reflection;
using DevExpress.Data.Filtering;
using DevExpress.XtraGrid.Columns;
using DBBase;

namespace Business
{
    public partial class anjianlogin : Form
    {
        public MainForm m_mainform;
        public bool byjgpy; 
        public bool bcheshu;
        public bool bchehua;
        public bool bclwyxjc;
        public bool blwcx;
        public bool bcltzcsjc;
        public bool baqzzjc;
        public bool bwaiguan;
        public bool bdipan;
        public bool bdongtai;
        public bool bwkcc;
        public bool bzbzl;
        public bool bzwd;
        public bool bywd;
        public bool bznd;
        public bool bynd;    
        public bool bzhidong1;
        public bool bzhidong2;
        public bool bzhidong3;
        public bool bzhidong4;
        public bool bzhidong5;
        public bool bzhidong6;
        public bool bzhuche1;
        public bool bzhuche2;
        public bool bzhuche3;
        public bool bzhuche4;
        public bool bzhuche5;
        public bool bzhuche6;
        public bool byzjzzd;
        public bool bezjzzd;
        public bool bszjzzd;
        public bool bsizjzzd;
        public bool bwzjzzd;
        public bool byzzz;
        public bool bezzz;
        public bool sanzz;
        public bool sizz;
        public bool wzzz;
        public bool lzzz;
        public bool bdlx;
        public bool bryjjx;
        public bool bxj;
        public bool blb;
        public bool bsds;
        public bool bzyjs;
        public bool bASM;
        public bool bLUG;
        public static string slshkt;//流水号抬头
        public static string scpcsz;//车牌初始值
        public static string sajsfzdsc;//安检删除
        public static string sdgpyjy;
        public bool sNetworking;//是否联网

        public bool jclbtxt = true;

        public bool bjzzdjy;//是否检测加载制动
        public bool bdgpyjy;//是否检测灯光偏移
        public bool bzjed;//是否只检2灯
        public bool bdysqb;//是否自动打印申请表
        public bool blushi;
        public bool bReCheck;
        public static string sjclb;
        public static string sjclb2;
        public int m_iIterat;
        public int m_iIterat2;
        public int iExamID;
        public int iDetectID;
        public int m_iPreDetectID;
        public bool bxianchengtuichu;
        public string shpcsh;
        public int izhoushu;
        public static string sycy;
        public int iAT_ID;
        public int iPreDetectid;


        public static string sjyjgbh;//检测站编号
        public static string surl;
        public static string sSQM;
        public bool bLowSpeed;
        public bool bdgpysfpd;
        public static string szhuren;
        public static string slushi;
        public static string swaiguan;
        public static string sdipan;
        public static string sdongtai;
        public string sdlr;
        public int iqdlkzzl;//驱动轮空载质量
        public string sDET_PRNTNOZJ;

        public static string qichejcxlb;//
        public static string motojcxlb;//
        public bool byygn=false;
         
        public string jyxm_sql;
        public string jyxm_Recheck;
        public string cjjyxm;
        public string zcfj = "";
        public string sjcbz = "21861";

        public anjianlogin(string bdly)
        {
            sdlr = bdly;
            InitializeComponent();
            geturl();
        }

        public void geturl()
        {
            Query mquery = new Query();
            string ssql;
            ssql = string.Format(@"Select * From StationInfor ");

            surl = mquery.GetDBString(ssql, "SI_WEB");
            sjyjgbh = mquery.GetDBString(ssql, "SI_JCZBH");
            sSQM = mquery.GetDBString(ssql, "SI_SQM");
            slshkt = mquery.GetDBString(ssql, "SI_LSHKT").Trim();
            shpcsh = mquery.GetDBString(ssql, "SI_HPCSZ");
            scpcsz = mquery.GetDBString(ssql, "SI_HPCSZ");//车牌初始值
            sajsfzdsc = mquery.GetDBString(ssql, "SI_AJSC");//安检删除
            sdgpyjy = mquery.GetDBString(ssql, "SI_DGPYJY");//灯光偏移检验
            sjcbz = mquery.GetDBString(ssql, "Standard");//检测标准
            sNetworking = bool.Parse(mquery.GetDBString(ssql, "SI_Networking"));//联网

            qichejcxlb = mquery.GetDBString(ssql, "SI_QicheJCXLB"); //dt.Rows[0]["SI_QicheJCXLB"].ToString().Trim();
            motojcxlb   = mquery.GetDBString(ssql, "SI_MotoJCXLB"); //dt.Rows[0]["SI_MotoJCXLB"].ToString().Trim();
            if (mquery.GetDBString(ssql, "SI_SQB") == "1")
            {
                bdysqb = true;
            }
            else
            {
                bdysqb = false;
            }
        }

        private float X;
        private float Y;

        private void setTag(Control cons)
        {
            foreach (Control con in cons.Controls)
            {
                con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
                if (con.Controls.Count > 0)
                    setTag(con);
            }
        }

        private void setControls(float newx, float newy, Control cons)
        {
            foreach (Control con in cons.Controls)
            {

                string[] mytag = con.Tag.ToString().Split(new char[] { ':' });
                float a = Convert.ToSingle(mytag[0]) * newx;
                con.Width = (int)a;
                a = Convert.ToSingle(mytag[1]) * newy;
                con.Height = (int)(a);
                a = Convert.ToSingle(mytag[2]) * newx;
                con.Left = (int)(a);
                a = Convert.ToSingle(mytag[3]) * newy;
                con.Top = (int)(a);
                Single currentSize = Convert.ToSingle(mytag[4]) * Math.Min(newx, newy);
                if (currentSize <= 0)
                {
                    currentSize = 0.1f;
                }
                con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
                if (con.Controls.Count > 0)
                {
                    setControls(newx, newy, con);
                }
            }

        }

        void Form1_Resize(object sender, EventArgs e)
        {
            float newx = (this.Width) / X;
            float newy = this.Height / Y;
            setControls(newx, newy, this);
            this.Text = this.Width.ToString() + " " + this.Height.ToString();

        }

        private void anjianlogin_Load(object sender, EventArgs e)
        {
            this.Resize += new EventHandler(Form1_Resize); this.Resize += new EventHandler(Form1_Resize);

            X = this.Width;
            Y = this.Height;


            setTag(this);
            Form1_Resize(new object(), new EventArgs());//x,y可在实例化时赋值,最后这句是新加的，在MDI时有用

            inicbx(text_CLLX, "table_cllx");
            inicbx(text_rlzl, "table_rlzl");
            inicbx(com_csys, "table_csys");

            inicbx(text_dengzhi, "table_dz");
            inicbx(text_dlxj, "table_xjxs");
            inicbx(com_sslb, "table_sslb");
            inicbx(com_jclb, "table_jclb");
            inicbx(com_qdxs, "table_qdxs");
            inicbx(cbxABS, "table_ABS");
            inicbx(c_生产单位, "table_scdw");
            
            text_hphm.Text = shpcsh;
            com_jclb.Text = "";

            text_dengzhi.Text = "03-二灯远近光";
            text_CLLX.Text = "";


            getclcp();
        }

        void inicbx(System.Windows.Forms.ComboBox cbx, string dataname)
        {
            Query objquery = new Query();
            string ssqlex = "";
            ssqlex = string.Format(@"select * from {0} order by table_1", dataname);
            DataTable dt = objquery.GetTable(ssqlex);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cbx.Items.Add(dt.Rows[i]["table_2"].ToString().Trim());
                if (i == 0)
                    cbx.Text = dt.Rows[0]["table_2"].ToString().Trim();
            }         
        }

        public class Product
        {
            public string ID { get; set; }
            public string name { get; set; }
        }

        public void getchaxun(string shphm, string shpzl)
        {
            text_hphm.Text = shphm;
            if (getautos())
            {
                jclbtxt = true;
                checkfujian(true);
            }

        }

        private void but_chaxun_Click(object sender, EventArgs e)
        { 
            if (getautos())
            {
                jclbtxt = true;
                checkfujian(true);
            }
        }

        private void but_qinkong_Click(object sender, EventArgs e)
        {
            clear();         
        }

        private void but_baocun_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("确定保存？", "提示", MessageBoxButtons.OKCancel);
            if (result == DialogResult.OK)
            {
                insertautos();
                MessageBox.Show("保存成功", "提示", MessageBoxButtons.OKCancel);
            }           
        }   
       
        private void but_queding_Click(object sender, EventArgs e)
        {
            var at_id = 0;
            iPreDetectid = 0;
            sjyxm = text_jcxm.Text;
            sjclb = com_jclb.Text;
            if (che_fujian.Checked)
            {
                bReCheck = true;
            }
            at_id = insertautos();//写入到车辆信息表
            UpdateAutosXZ(at_id);
            insertDetects_SJA(at_id, com_jclb.Text);
            insertDetects_SJB(iDetectID);
            insertDetects_SJC(iDetectID);
            insertDetects_SJD(iDetectID);
            insertPD_AJ(iDetectID);
            //更新所有项目的检测次数
            update_JYCS(iDetectID);
            UpdateModel();
            clear();   
        }

        public bool getautos()
        {
            Query mquery = new Query();
            string at_id ="";
            string sql;
            sql = string.Format(@"Select *  from Auto Where AT_HPHM='{0}' ", text_hphm.Text.Trim());
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {

                text_clsbm.Text = dt.Rows[0]["AT_VIN"].ToString().Trim();
                text_fdjh.Text = dt.Rows[0]["AT_FDJH"].ToString().Trim();

                text_CLLX.Text = dt.Rows[0]["AT_CLLX"].ToString().Trim();
                cxbclpp.Text = dt.Rows[0]["AT_CLZWPP"].ToString().Trim();
                cxbcxdm.Text = dt.Rows[0]["AT_CLXH"].ToString().Trim();
                text_dengzhi.Text = dt.Rows[0]["AT_LAMP"].ToString().Trim();
                text_rlzl.Text = dt.Rows[0]["AT_RYZL"].ToString().Trim();
                text_zzl.Text = dt.Rows[0]["AT_ZZL"].ToString().Trim();
                text_zbzl.Text = dt.Rows[0]["AT_ZBZL"].ToString().Trim();
                text_hzzl.Text = dt.Rows[0]["AT_HDZZL"].ToString().Trim();
                text_zws.Text = dt.Rows[0]["AT_HDZK"].ToString().Trim();
                com_csys.Text = dt.Rows[0]["AT_CSYS"].ToString().Trim();
                text_dlxj.Text = dt.Rows[0]["AT_SUTYPE"].ToString().Trim();
                text_zzs.Text = dt.Rows[0]["AT_ZS"].ToString().Trim();
                com_zzzw.Text = dt.Rows[0]["AT_ZCZW"].ToString().Trim();
                text_gl.Text = dt.Rows[0]["AT_GL"].ToString().Trim();
                com_sslb.Text = dt.Rows[0]["AT_SSLB"].ToString().Trim();

                com_qdxs.Text = dt.Rows[0]["AT_QDFS"].ToString().Trim();
                at_id = dt.Rows[0]["AT_ID"].ToString().Trim();
                cbxABS.Text = dt.Rows[0]["AT_OBD"].ToString().Trim();
                c_生产单位.Text = dt.Rows[0]["AT_CCCS"].ToString().Trim();

                string sat_id = dt.Rows[0]["AT_ID"].ToString().Trim();
                sql = string.Format(@"Select DETECT_ID,DET_JCLB From Detects_SJA where AT_ID={0} order by DETECT_ID desc", sat_id);
                com_jclb.Text = mquery.GetDBString(sql, "DET_JCLB");
                return true;
            }
            else
            {
                MessageBox.Show("没找到该车辆档案");
                text_clsbm.Focus();
            }
            return false;
        }

        public string getsqlmessage(string stable, string smessage)//获取SQL数据中对应信息
        {
            Query objquery = new Query();
            string ssqlex = "";
            ssqlex = string.Format(@"select * from {0} where table_2='{1}'", stable, smessage);
            DataTable dt = objquery.GetTable(ssqlex);
            if (dt.Rows.Count > 0)
            {

                return dt.Rows[0]["table_1"].ToString().Trim();
            }
            else
            {
                return "";
            }

        }

        public string getsqlmessagetable2(string stable, string smessage)
        {
            Query objquery = new Query();
            string ssqlex = "";
            ssqlex = string.Format(@"select * from {0} where table_1='{1}'", stable, smessage);
            DataTable dt = objquery.GetTable(ssqlex);
            if (dt.Rows.Count > 0)
            {
                return dt.Rows[0]["table_2"].ToString().Trim();
            }
            else
            {
                return "";
            }

        }

        public void clear()
        {
            text_hphm.Text = shpcsh;
            text_hphm.Focus();
            text_hphm.Select(text_hphm.Text.Length, 0);
            text_clsbm.Text = "";
            text_fdjh.Text = "";
            text_CLLX.Text = "";
            cxbclpp.Text = "";
            cxbcxdm.Text = "";
            text_dengzhi.Text = "03-二灯远近光";
            text_rlzl.Text = "A-汽油";
            text_zzl.Text = "";
            text_zbzl.Text = "";
            text_hzzl.Text = "0";
            text_zws.Text = "";
            com_csys.Text = "";
            text_dlxj.Text = "1-非独立悬架";
            text_zzs.Text = "";
            com_zzzw.Text = "";
            text_gl.Text = "";
            com_sslb.Text = "";
            com_jclb.Text = "";
            text_jcxm.Text = "";
            text_zzs.Text = "2";
            com_zzzw.Text = "2";
            com_qdxs.Text = "02-后驱";

            com_sslb.SelectedIndex = -1;
            com_jclb.SelectedIndex = -1;
        }

        public int insertautos()
        {
            Query mquery = new Query();
            string sql;
            sql = string.Format(@"Select * from AUTO Where AT_HPHM='{0}'", text_hphm.Text);
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                sql = string.Format(@"update  AUTO set AT_VIN='{0}',   
                                                        AT_FDJH='{1}',
                                                        AT_CLLX='{2}',
                                                        AT_CLZWPP='{3}',
                                                        AT_CLXH='{4}',
                                                        AT_LAMP='{5}',
                                                        AT_RYZL='{6}',
                                                        AT_ZZL={7},
                                                        AT_ZBZL={8},
                                                        AT_HDZZL={9},
                                                        AT_HDZK={10},
                                                        AT_CSYS='{11}',
                                                        AT_SUTYPE='{12}',
                                                        AT_ZS='{13}',
                                                        AT_ZCZW='{14}',
                                                        AT_CHANG='{15}',
                                                        AT_KUAN='{16}',
                                                        AT_GAO='{17}',
                                                        AT_GL='{18}',
                                                        AT_ZJ='{19}',
                                                        AT_QLJ='{20}',
                                                        AT_HLJ='{21}',
                                                        AT_SSLB='{22}', 
                                                        AT_QDFS='{23}',
                                                        AT_OBD='{24}',
                                                        AT_CCCS='{26}'
                                                 where  AT_HPHM ='{25}'",
                                                        text_clsbm.Text,
                                                        text_fdjh.Text,
                                                        text_CLLX.Text,
                                                        cxbclpp.Text,
                                                        cxbcxdm.Text,
                                                        text_dengzhi.Text,
                                                        text_rlzl.Text,
                                                        text_zzl.Text,
                                                        text_zbzl.Text,
                                                        text_hzzl.Text,
                                                        text_zws.Text,
                                                        com_csys.Text,
                                                        text_dlxj.Text,
                                                        text_zzs.Text,
                                                        com_zzzw.Text,
                                                        "",
                                                        "",
                                                        "",
                                                        text_gl.Text,
                                                        "",
                                                        "",
                                                        "",
                                                        com_sslb.Text,
                                                        com_qdxs.Text,
                                                        cbxABS.Text,
                                                        text_hphm.Text,
                                                        c_生产单位.Text);
                //c_生产单位.Text = dt.Rows[0]["AT_CCCS"].ToString().Trim();
            }
            else
            {
                sql = string.Format(@"Insert Into AUTO(AT_HPHM,                                                
                                                        AT_VIN,   
                                                        AT_FDJH,                                                         
                                                        AT_CLLX,
                                                        AT_CLZWPP,
                                                        AT_CLXH,
                                                        AT_LAMP,
                                                        AT_RYZL,                                                       
                                                        AT_ZZL,
                                                        AT_ZBZL,
                                                        AT_HDZZL,
                                                        AT_HDZK,
                                                        AT_CSYS,
                                                        AT_SUTYPE,                                                      
                                                        AT_ZS,
                                                        AT_ZCZW,
                                                        AT_CHANG,
                                                        AT_KUAN,
                                                        AT_GAO,                    
                                                        AT_GL,
                                                        AT_ZJ,
                                                        AT_QLJ,
                                                        AT_HLJ,                      
                                                        AT_SSLB,                      
                                                        AT_QDFS,
                                                        AT_OBD,
                                                        AT_CCCS) Values(
                                                        '{0}',
                                                        '{1}',
                                                        '{2}',
                                                        '{3}',
                                                        '{4}',
                                                        '{5}',
                                                        '{6}',
                                                        '{7}',
                                                        '{8}',
                                                        '{9}',
                                                        '{10}',
                                                        '{11}',
                                                        '{12}',
                                                        '{13}',
                                                        '{14}',
                                                        '{15}',
                                                        '{16}',
                                                        '{17}',
                                                        '{18}',
                                                        '{19}',
                                                        '{20}',
                                                        '{21}',
                                                        '{22}',
                                                        '{23}',
                                                        '{24}',
                                                        '{25}',
                                                        '{26}')",
                                                        text_hphm.Text,
                                                        text_clsbm.Text,
                                                        text_fdjh.Text,
                                                        text_CLLX.Text,
                                                        cxbclpp.Text,
                                                        cxbcxdm.Text,
                                                        text_dengzhi.Text,
                                                        text_rlzl.Text,
                                                        text_zzl.Text,
                                                        text_zbzl.Text,
                                                        text_hzzl.Text,
                                                        text_zws.Text,
                                                        com_csys.Text,
                                                        text_dlxj.Text,
                                                        text_zzs.Text,
                                                        com_zzzw.Text,
                                                        "",
                                                        "",
                                                        "",
                                                        text_gl.Text,
                                                        "",
                                                        "",
                                                        "",
                                                        com_sslb.Text,
                                                        com_qdxs.Text,
                                                        cbxABS.Text,
                                                        c_生产单位.Text);

            }
            mquery.InsertDB(sql);
            m_mainform.saveriji(sql);//保存操作日记
            sql = string.Format(@"Select AT_ID from AUTO Where AT_HPHM='{0}' order by AT_ID desc", text_hphm.Text);
            var date = mquery.GetDBInt(sql, "AT_ID");
            return date;

        }

        public string sjyxm;
        public int ijycs_sc;
        public void insertDetects_SJA(int iat_id, string jclb)
        {
            var jylsh = "";
            var sql = "";
            if (!bReCheck)
            {
                sql = string.Format(@"Insert Into Detects_SJA(
                                        [AT_ID]
                                        ,[DET_JCLB]
                                        ,[DET_JYXM]
                                        ,[DET_BJYXM]
                                        ,DET_DATE
                                        ,DET_JYDATE
                                        ,DET_JYCS
                                        ,DET_JYZJL
                                        ,DET_DLY
                                        ,DET_YCY
                                        ,DET_FINISH
                                        ,DET_BWEIGHT
                                        ,DET_BSLTJ
                                        ,DET_BExamine) Values(
                                         {0},
                                        '{1}',
                                        '{2}',
                                        '{3}',
                                        '{4}',
                                        '{5}',
                                         {6},
                                         {7},
                                        '{8}',
                                        '{9}',
                                         {10},
                                         {11},
                                         {12},
                                         {13})",
                                        iat_id,
                                        jclb,
                                        sjyxm,
                                        sjyxm,
                                        DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                        DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                        1,
                                        0,
                                        sdlr,
                                        "",
                                        0,
                                        1,
                                        0,
                                        0);
                Query mquery = new Query();
                if (mquery.InsertDB(sql))
                {
                    //查询流水号
                    sql = string.Format(@"Select DETECT_ID From Detects_SJA where AT_ID={0} and DET_JCLB='{1}' order by DETECT_ID desc",
                                          iat_id, jclb);
                    iDetectID = mquery.GetDBInt(sql, "DETECT_ID");
                    sql = string.Format("Select jylsh_NO from jylsh where jylsh_date='{0}'  ", DateTime.Now.ToString("yyyyMMdd"));
                    int idatecount = mquery.GetDBInt(sql, "jylsh_NO");
                    if (idatecount < 1)
                    {
                        idatecount = 0;
                        sql = string.Format(@"Insert Into jylsh ([jylsh_date],[jylsh_NO])Values('{0}',{1})", DateTime.Now.ToString("yyyyMMdd"), 1);
                    }
                    else
                    {

                        sql = string.Format("update jylsh set jylsh_NO={0} where  jylsh_date='{1}' ", idatecount + 1, DateTime.Now.ToString("yyyyMMdd"));
                    }
                    mquery.InsertDB(sql);

                    idatecount = idatecount + 1;
                    string slssj = DateTime.Now.ToString("yyMMdd");
                    if (slshkt.Length == 6)
                    {
                        jylsh = string.Format("{0}{1}{2}", slshkt, slssj, idatecount.ToString("00000"));//检验流水号
                    }
                    else if (slshkt.Length > 6)
                    {
                        jylsh = string.Format("{0}{1}", slshkt, slssj);
                        int a = 17 - jylsh.Length;
                        string sbw = idatecount.ToString().PadLeft(a, '0');
                        jylsh = string.Format("{0}{1}{2}", slshkt, slssj, sbw);//检验流水号
                    }
                    else if (slshkt.Length < 6)
                    {
                        slssj = DateTime.Now.ToString("yyyyMMdd");
                        jylsh = string.Format("{0}{1}{2}", slshkt, slssj, idatecount.ToString("000000"));//检验流水号
                    }

                    sql = string.Format("update Detects_SJA set DET_LSH='{0}' where DETECT_ID={1} ", jylsh, iDetectID);
                    mquery.InsertDB(sql);

                }
            }
            else
            {
                ijycs_sc = 0;
                Query mquery = new Query();
                sql = string.Format(@"Select DETECT_ID From Detects_SJA where AT_ID={0} and DET_JCLB='{1}' order by DETECT_ID desc",
                                        iat_id, jclb);
                var idata = 0;
                idata = mquery.GetDBInt(sql, "DETECT_ID");
                iPreDetectid = idata;
                sql = string.Format(@"insert into Detects_SJA([AT_ID]
      ,[DET_JCLB]
      ,[DET_LSH]
      ,[DET_LSHZJ]
      ,[DET_JYXM]
      ,[DET_BJYXM]
      ,[DET_Location]
      ,[DET_JYCS]
      ,[DET_JCXH]
      ,[DET_DATE]
      ,[DET_JYDATE]
      ,[DET_DLY]
      ,[DET_YCY]
      ,[DET_CZY]
      ,[DET_WJCZY]
      ,[DET_DPCZY]
      ,[DET_DTCZY]
      ,[DET_LSCZY]
      ,[DET_WJ]
      ,[DET_WJJL]
      ,[DET_WJCS]
      ,[DET_DYNA]
      ,[DET_DYNAJL]
      ,[DET_DYNACS]
      ,[DET_DC]
      ,[DET_DCJL]
      ,[DET_DCCS]
      ,[DET_WKCCC]
      ,[DET_WKCCK]
      ,[DET_WKCCG]
      ,[DET_WKCJL]
      ,[DET_WKKJL]
      ,[DET_WKGJL]
      ,[DET_WKCCJL]
      ,[DET_WKCCCS]
      ,[DET_ZBZL]
      ,[DET_ZBZLJL]
      ,[DET_ZBZLCS]
      ,[DET_SPEED]
      ,[DET_SPEEDJL]
      ,[DET_SPEEDCS]
      ,[DET_SLIP]
      ,[DET_SLIPJL]
      ,[DET_SLIP2]
      ,[DET_SLIPJL2]
      ,[DET_SLIPCS]
      ,[DET_ZWDGQ]
      ,[DET_ZWDGQJL]
      ,[DET_ZWYGCZPYL]
      ,[DET_ZWYGCZPY]
      ,[DET_ZWYGCZPYJL]
      ,[DET_ZWYGSPPY]
      ,[DET_ZWYGSPPYJL]
      ,[DET_ZWYGDG]
      ,[DET_ZWJGCZPYL]
      ,[DET_ZWJGCZPY]
      ,[DET_ZWJGCZPYJL]
      ,[DET_ZWJGSPPY]
      ,[DET_ZWJGSPPYJL]
      ,[DET_ZWJGDG]
      ,[DET_ZWDJL]
      ,[DET_ZWDCS]
      ,[DET_ZNDGQ]
      ,[DET_ZNDGQJL]
      ,[DET_ZNYGCZPYL]
      ,[DET_ZNYGCZPY]
      ,[DET_ZNYGCZPYJL]
      ,[DET_ZNYGSPPY]
      ,[DET_ZNYGSPPYJL]
      ,[DET_ZNYGDG]
      ,[DET_ZNJGCZPYL]
      ,[DET_ZNJGCZPY]
      ,[DET_ZNJGCZPYJL]
      ,[DET_ZNJGSPPY]
      ,[DET_ZNJGSPPYJL]
      ,[DET_ZNJGDG]
      ,[DET_ZNDJL]
      ,[DET_ZNDCS]
      ,[DET_YWDGQ]
      ,[DET_YWDGQJL]
      ,[DET_YWYGCZPYL]
      ,[DET_YWYGCZPY]
      ,[DET_YWYGCZPYJL]
      ,[DET_YWYGSPPY]
      ,[DET_YWYGSPPYJL]
      ,[DET_YWYGDG]
      ,[DET_YWJGCZPYL]
      ,[DET_YWJGCZPY]
      ,[DET_YWJGCZPYJL]
      ,[DET_YWJGSPPY]
      ,[DET_YWJGSPPYJL]
      ,[DET_YWJGDG]
      ,[DET_YWDJL]
      ,[DET_YWDCS]
      ,[DET_YNDGQ]
      ,[DET_YNDGQJL]
      ,[DET_YNYGCZPYL]
      ,[DET_YNYGCZPY]
      ,[DET_YNYGCZPYJL]
      ,[DET_YNYGSPPY]
      ,[DET_YNYGSPPYJL]
      ,[DET_YNYGDG]
      ,[DET_YNJGCZPYL]
      ,[DET_YNJGCZPY]
      ,[DET_YNJGCZPYJL]
      ,[DET_YNJGSPPY]
      ,[DET_YNJGSPPYJL]
      ,[DET_YNJGDG]
      ,[DET_YNDJL]
      ,[DET_YNDCS]
      ,[DET_JYZJL]) 
      select [AT_ID]
      ,[DET_JCLB]
      ,[DET_LSH]
      ,[DET_LSHZJ]
      ,[DET_JYXM]
      ,[DET_BJYXM]
      ,[DET_Location]
      ,[DET_JYCS]
      ,[DET_JCXH]
      ,[DET_DATE]
      ,[DET_JYDATE]
      ,[DET_DLY]
      ,[DET_YCY]
      ,[DET_CZY]
      ,[DET_WJCZY]
      ,[DET_DPCZY]
      ,[DET_DTCZY]
      ,[DET_LSCZY]
      ,[DET_WJ]
      ,[DET_WJJL]
      ,[DET_WJCS]
      ,[DET_DYNA]
      ,[DET_DYNAJL]
      ,[DET_DYNACS]
      ,[DET_DC]
      ,[DET_DCJL]
      ,[DET_DCCS]
      ,[DET_WKCCC]
      ,[DET_WKCCK]
      ,[DET_WKCCG]
      ,[DET_WKCJL]
      ,[DET_WKKJL]
      ,[DET_WKGJL]
      ,[DET_WKCCJL]
      ,[DET_WKCCCS]
      ,[DET_ZBZL]
      ,[DET_ZBZLJL]
      ,[DET_ZBZLCS]
      ,[DET_SPEED]
      ,[DET_SPEEDJL]
      ,[DET_SPEEDCS]
      ,[DET_SLIP]
      ,[DET_SLIPJL]
      ,[DET_SLIP2]
      ,[DET_SLIPJL2]
      ,[DET_SLIPCS]
      ,[DET_ZWDGQ]
      ,[DET_ZWDGQJL]
      ,[DET_ZWYGCZPYL]
      ,[DET_ZWYGCZPY]
      ,[DET_ZWYGCZPYJL]
      ,[DET_ZWYGSPPY]
      ,[DET_ZWYGSPPYJL]
      ,[DET_ZWYGDG]
      ,[DET_ZWJGCZPYL]
      ,[DET_ZWJGCZPY]
      ,[DET_ZWJGCZPYJL]
      ,[DET_ZWJGSPPY]
      ,[DET_ZWJGSPPYJL]
      ,[DET_ZWJGDG]
      ,[DET_ZWDJL]
      ,[DET_ZWDCS]
      ,[DET_ZNDGQ]
      ,[DET_ZNDGQJL]
      ,[DET_ZNYGCZPYL]
      ,[DET_ZNYGCZPY]
      ,[DET_ZNYGCZPYJL]
      ,[DET_ZNYGSPPY]
      ,[DET_ZNYGSPPYJL]
      ,[DET_ZNYGDG]
      ,[DET_ZNJGCZPYL]
      ,[DET_ZNJGCZPY]
      ,[DET_ZNJGCZPYJL]
      ,[DET_ZNJGSPPY]
      ,[DET_ZNJGSPPYJL]
      ,[DET_ZNJGDG]
      ,[DET_ZNDJL]
      ,[DET_ZNDCS]
      ,[DET_YWDGQ]
      ,[DET_YWDGQJL]
      ,[DET_YWYGCZPYL]
      ,[DET_YWYGCZPY]
      ,[DET_YWYGCZPYJL]
      ,[DET_YWYGSPPY]
      ,[DET_YWYGSPPYJL]
      ,[DET_YWYGDG]
      ,[DET_YWJGCZPYL]
      ,[DET_YWJGCZPY]
      ,[DET_YWJGCZPYJL]
      ,[DET_YWJGSPPY]
      ,[DET_YWJGSPPYJL]
      ,[DET_YWJGDG]
      ,[DET_YWDJL]
      ,[DET_YWDCS]
      ,[DET_YNDGQ]
      ,[DET_YNDGQJL]
      ,[DET_YNYGCZPYL]
      ,[DET_YNYGCZPY]
      ,[DET_YNYGCZPYJL]
      ,[DET_YNYGSPPY]
      ,[DET_YNYGSPPYJL]
      ,[DET_YNYGDG]
      ,[DET_YNJGCZPYL]
      ,[DET_YNJGCZPY]
      ,[DET_YNJGCZPYJL]
      ,[DET_YNJGSPPY]
      ,[DET_YNJGSPPYJL]
      ,[DET_YNJGDG]
      ,[DET_YNDJL]
      ,[DET_YNDCS]
      ,[DET_JYZJL] from Detects_SJA where DETECT_ID='{0}'", idata);
                mquery.InsertDB(sql);
                //查询流水号
                sql = string.Format(@"Select DETECT_ID,DET_JYCS,DET_LSH From Detects_SJA where AT_ID={0} and DET_JCLB='{1}' order by DETECT_ID desc",
                                      iat_id, jclb);
                iDetectID = mquery.GetDBInt(sql, "DETECT_ID");
                ijycs_sc = mquery.GetDBInt(sql, "DET_JYCS");
                jylsh = mquery.GetDBString(sql, "DET_LSH");
                sql = string.Format(@"update Detects_SJA set
                                                DET_BJYXM='{0}',
                                                DET_DATE='{3}',
                                                DET_BWEIGHT=1,
                                                DET_FINISH=0,
                                                DET_JYCS={1},
                                                DET_Location='等待复检开始',
                                                DET_JYZJL='',
                                                DET_BExamine=0 
                 where DETECT_ID={2} ", sjyxm, ijycs_sc + 1, iDetectID, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                mquery.InsertDB(sql);

            }
        }

        public void insertDetects_SJB(int iDetectid)
        {
            var sql = "";
            if (!bReCheck)
            {
                sql = string.Format("Insert Into Detects_SJB(DETECT_ID) Values({0})", iDetectID);
            }
            else
            {
                sql = string.Format(@"Select * into #temp1 from Detects_SJB where DETECT_ID={0}  update #temp1 set DETECT_ID={1} insert Detects_SJB  select * from #temp1",
              iPreDetectid, iDetectid);
            }
            Query mquery = new Query();
            mquery.InsertDB(sql);

        }

        public void insertDetects_SJC(int iDetectid)
        {
            string UpdateDatas;
            if (!bReCheck)
            {
                UpdateDatas = string.Format("Insert Into Detects_SJC(DETECT_ID) Values({0})", iDetectID);
            }
            else
            {
                UpdateDatas = string.Format(@"Select * into #temp1 from Detects_SJC where DETECT_ID={0}  update #temp1 set DETECT_ID={1} insert Detects_SJC  select * from #temp1",
              iPreDetectid, iDetectid);
            }
            Query mquery = new Query();
            mquery.InsertDB(UpdateDatas);

        }

        public void insertDetects_SJD(int iDetectid)
        {
            string UpdateDatas;
            if (!bReCheck)
            {
                UpdateDatas = string.Format("Insert Into Detects_SJD(DETECT_ID) Values({0})", iDetectID);
            }
            else
            {
                UpdateDatas = string.Format(@"Select * into #temp1 from Detects_SJD where DETECT_ID={0}  update #temp1 set DETECT_ID={1} insert Detects_SJD  select * from #temp1",
              iPreDetectid, iDetectid);
            }
            Query mquery = new Query();
            mquery.InsertDB(UpdateDatas);

        }

        public void insertPD_AJ(int iDetectid)
        {
            var sql = "";
            if (!bReCheck)
            {
                sql = string.Format("Insert Into PD_AJ(DETECT_ID) Values({0})", iDetectID);
            }
            else
            {
                sql = string.Format(@"Select * into #temp1 from PD_AJ where DETECT_ID={0}  update #temp1 set DETECT_ID={1} insert PD_AJ  select * from #temp1",
              iPreDetectid, iDetectid);
            }
            Query mquery = new Query();
            mquery.InsertDB(sql);

        }

        public void update_JYCS(int iDetectid)
        {
            var sql = "";
            Query mquery = new Query();
            string[] WJJLZD = new string[] { "DET_WYXJL", "DET_LWCXJL", "DET_TZCSJL", "DET_AQZZJL" };
            string[] Detects_SJAJL_zidu = { "DET_WJJL", "DET_DYNAJL", "DET_DCJL", "DET_WKCCJL", "DET_ZBZLJL", "DET_SPEEDJL", "DET_SLIPJL", "DET_ZWDJL", "DET_ZNDJL", "DET_YNDJL", "DET_YWDJL" };
            string[] Detects_SJA_zidu = { "DET_WJCS", "DET_DYNACS", "DET_DCCS", "DET_WKCCCS", "DET_ZBZLCS", "DET_SPEEDCS", "DET_SLIPCS", "DET_ZWDCS", "DET_ZNDCS", "DET_YNDCS", "DET_YWDCS" };
            string[] Detects_SJA_jyxm = { "F1", "DC", "C1", "M1", "Z1", "S1", "A1", "H1", "H2", "H3", "H4" };
            for (int i = 0; i < Detects_SJA_zidu.Length; i++)
            {
                if (text_jcxm.Text.Contains(Detects_SJA_jyxm[i]) || (text_dengzhi.Text.Contains("四灯") && (Detects_SJA_zidu[i].Contains("DET_ZNDCS") || Detects_SJA_zidu[i].Contains("DET_YNDCS"))))
                {
                    sql = string.Format(@"select {0} from Detects_SJA where DETECT_ID={1}", Detects_SJA_zidu[i], iDetectid);
                    var data = "";
                    data = mquery.GetDBString(sql, Detects_SJA_zidu[i]);
                    int idata = 0;
                    int.TryParse(data, out idata);
                    sql = string.Format(@"update Detects_SJA set {0}={1} where  DETECT_ID={2}", Detects_SJA_zidu[i], idata + 1, iDetectid);
                    mquery.InsertDB(sql);
                    if (!bReCheck)
                    {
                        sql = string.Format(@"update Detects_SJA set {0}={1} where  DETECT_ID={2}", Detects_SJAJL_zidu[i], "0", iDetectid);
                        mquery.InsertDB(sql);
                        if (i < 1)
                        {
                            for (int j = 0; j < WJJLZD.Length; j++)
                            {
                                sql = string.Format(@"update Detects_SJA set {0}={1} where  DETECT_ID={2}", WJJLZD[j], "0", iDetectid);
                                mquery.InsertDB(sql);
                            }
                        }
                    }
                }
            }

            string[] Detects_SJBJL_zidu = { "DET_ZZJL1", "DET_ZZJL2", "DET_ZZJL3", "DET_ZZJL4", "DET_ZZJL5", "DET_ZCJL", "DET_SSJL" };
            string[] Detects_SJB_zidu = { "DET_BRIKECS1", "DET_BRIKECS2", "DET_BRIKECS3", "DET_BRIKECS4", "DET_BRIKECS5", "DET_ZCCS", "DET_SSCS" };
            string[] Detects_SJB_jyxm = { "B1", "B2", "B3", "B4", "B5", "B", "B0" };
            for (int i = 0; i < Detects_SJB_zidu.Length; i++)
            {
                if (text_jcxm.Text.Contains(Detects_SJB_jyxm[i]))
                {
                    sql = string.Format(@"select {0} from Detects_SJB where DETECT_ID={1}", Detects_SJB_zidu[i], iDetectid);
                    var data = "";
                    data = mquery.GetDBString(sql, Detects_SJB_zidu[i]);
                    int idata = 0;
                    int.TryParse(data, out idata);
                    sql = string.Format(@"update Detects_SJB set {0}={1} where  DETECT_ID={2}", Detects_SJB_zidu[i], idata + 1, iDetectid);
                    mquery.InsertDB(sql);
                    if (!bReCheck)
                    {
                        sql = string.Format(@"update Detects_SJB set {0}={1} where  DETECT_ID={2}", Detects_SJBJL_zidu[i], "0", iDetectid);
                        mquery.InsertDB(sql);
                    }
                }
            }
            string[] Detects_SJCJL_zidu = { "DET_DLXJL", "DET_YHJL", "DET_XJJL1", "DET_XJJL2", "DET_LAJL" };
            string[] Detects_SJC_zidu = { "DET_DLXCS", "DET_RYJJXCS", "DET_XJCS1", "DET_XJCS2", "DET_LBCS" };
            string[] Detects_SJC_jyxm = { "DLX", "RYJJX", "XJ", "XJ", "SJ" };
            for (int i = 0; i < Detects_SJC_zidu.Length; i++)
            {
                if (text_jcxm.Text.Contains(Detects_SJC_jyxm[i]))
                {
                    sql = string.Format(@"select {0} from Detects_SJC where DETECT_ID={1}", Detects_SJC_zidu[i], iDetectid);
                    var data = "";
                    data = mquery.GetDBString(sql, Detects_SJC_zidu[i]);
                    int idata = 0;
                    int.TryParse(data, out idata);
                    sql = string.Format(@"update  Detects_SJC set {0}={1} where  DETECT_ID={2}", Detects_SJC_zidu[i], idata + 1, iDetectid);
                    mquery.InsertDB(sql);
                    if (!bReCheck)
                    {
                        sql = string.Format(@"update Detects_SJC set {0}={1} where  DETECT_ID={2}", Detects_SJCJL_zidu[i], "0", iDetectid);
                        mquery.InsertDB(sql);
                    }
                }
            }

        }

        public void UpdateAutosXZ(int iautosid)//限值标准
        {
            float STD_SLIPH, STD_SLIPL, STD_SPDOLO, STD_SPDOHI;
            Query mquery = new Query();
            string sql;
            sql = string.Format("Select * from Stands Where STD_ID={0}", 1);
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                float fSTD_SPEEDL = float.Parse(dt.Rows[0]["STD_SPEEDL"].ToString().Trim());
                float fSTD_SPEEDH = float.Parse(dt.Rows[0]["STD_SPEEDH"].ToString().Trim());

                float fSTD_NOISELOW = float.Parse(dt.Rows[0]["STD_NOISELOW"].ToString().Trim());//m_pDbCon->GetAsFloat("STD_NOISELOW",vVar);
                float fSTD_NOISEHIGH = float.Parse(dt.Rows[0]["STD_NOISEHIGH"].ToString().Trim());//m_pDbCon->GetAsFloat("STD_NOISEHIGH",vVar);
                float fSTD_SLIPLOW = float.Parse(dt.Rows[0]["STD_SLIPLOW"].ToString().Trim());//m_pDbCon->GetAsFloat("STD_SLIPLOW",vVar);
                float fSTD_SLIPHIGH = float.Parse(dt.Rows[0]["STD_SLIPHIGH"].ToString().Trim());//m_pDbCon->GetAsFloat("STD_SLIPHIGH",vVar);


                STD_SLIPH = fSTD_SLIPHIGH;//侧滑
                STD_SLIPL = fSTD_SLIPLOW;

                STD_SPDOLO = fSTD_SPEEDL;//车速
                STD_SPDOHI = fSTD_SPEEDH;


                Query mquerycx = new Query();
                string sqlcx;
                sqlcx = string.Format(@"select AT_ID FROM STAND_XZ where AT_ID={0}", iautosid);

                DataTable dtcx = mquery.GetTable(sqlcx);
                if (dtcx.Rows.Count > 0)
                {
                    sql = string.Format(@"update STAND_XZ set
                                    XZ_KZZD1={0},
                                    XZ_KZBPH1={1},
                                    XZ_KZZD2={2},
                                    XZ_KZBPH2={3},
                                    XZ_KZBPH3={4},
                                    XZ_JZZD={5},
                                    XZ_ZCZD={6},
                                    XZ_SSZD={7},
                                    XZ_LIGHT={8},
                                    XZ_YGCZSX={9},
                                    XZ_YGCZXX={10},
                                    XZ_JGCZSX={11},
                                    XZ_JGCZXX={12},
                                    XZ_SLIPH={13},
                                    XZ_SLIPL={14},
                                    XZ_SPDOHI={15},
                                    XZ_SPDOLO={16}
                                    where AT_ID={17}", 0,//0
                                0,//1
                                0,//2
                                0,//3
                                0,//4
                                0,//5
                                0,//6
                                0,//7
                                0,//8
                                0,//9
                                0,//10
                                0,//11
                                0,//12
                                STD_SLIPH,//13
                                STD_SLIPL,//14
                                STD_SPDOHI,//15
                                STD_SPDOLO,//16
                                iautosid);//17
                }
                else
                {
                    sql = string.Format(@"insert into STAND_XZ(
                                    AT_ID,
                                    XZ_KZZD1,
                                    XZ_KZBPH1,
                                    XZ_KZZD2,
                                    XZ_KZBPH2,
                                    XZ_KZBPH3,
                                    XZ_JZZD,
                                    XZ_ZCZD,
                                    XZ_SSZD,
                                    XZ_LIGHT,
                                    XZ_YGCZSX,
                                    XZ_YGCZXX,
                                    XZ_JGCZSX,
                                    XZ_JGCZXX,
                                    XZ_SLIPH,
                                    XZ_SLIPL,
                                    XZ_SPDOHI,
                                    XZ_SPDOLO) Values(
                                                {0},
                                                {1},
                                                {2},
                                                {3},
                                                {4},
                                                {5},
                                                {6},
                                                {7},
                                                {8},
                                                {9},
                                                {10},
                                                {11},
                                                {12},
                                                {13},
                                                {14},
                                                {15},
                                                {16},
                                                {17})", iautosid,//0
                                            0,
                                            0,
                                            0,
                                            0,
                                            0,
                                            0,
                                            0,
                                            0,
                                            0,
                                            0,
                                            0,
                                            0,
                                            0,
                                            STD_SLIPH,
                                            STD_SLIPL,
                                            STD_SPDOHI,
                                            STD_SPDOLO);
                }
                mquery.InsertDB(sql);
            }
        }

        private void com_jclb_SelectedIndexChanged(object sender, EventArgs e)
        {
            checkfujian(true);
        }

        public void checkfujian(bool bfujian)//bfujian 判断是否自动读这台是否复检
        {
            if (che_fujian.Checked == false)
            {
                bReCheck = false;
            }
            text_jcxm.Text = "";
            if (text_clsbm.Text.Length < 1)
            {
                return;
            }
            jyxm_Recheck = "";
            if (bfujian)
            {
                Query mquery = new Query();
                string sql = string.Format(@"SELECT Detects_SJA.DET_JYXM_Recheck,Detects_SJA.DET_JYXM FROM Detects_SJA,AUTO where Detects_SJA.AT_ID=AUTO.AT_ID and AT_HPHM='{0}' and DET_JCLB ='{1}' order by DETECT_ID desc", text_hphm.Text, com_jclb.Text);

                DataTable dt = mquery.GetTable(sql);
                if (dt.Rows.Count > 0)
                {
                    jyxm_Recheck = dt.Rows[0]["DET_JYXM_Recheck"].ToString().Trim();
                    che_fujian.Checked = true;
                }
                else
                {
                    che_fujian.Checked = false;
                }
            }
            //是否复检
            if (che_fujian.Checked)
            {
                text_jcxm.Text = jyxm_Recheck;
            }
            else
            {
                text_jcxm.Text = "S1,A1,B1,B2,B0,F1,C1,SJ,DC,H1,H4";
                if (text_zzs.Text=="3")
                {
                    text_jcxm.Text = "S1,A1,B1,B2,B3,B0,F1,C1,SJ,DC,H1,H4";
                }
            }
        }

        private void label33_Click(object sender, EventArgs e)
        {
            jcxm m_jcxm = new jcxm(text_jcxm.Text, "1", che_fujian.Checked,"");
            m_jcxm.ShowDialog();

            if (m_jcxm.DialogResult == DialogResult.OK)
            {
                text_jcxm.Text = m_jcxm.sjcxm;
            }
        }

        private void che_fujian_CheckedChanged(object sender, EventArgs e)
        {
            checkfujian(che_fujian.Checked);
        }

        private void but_download_Click(object sender, EventArgs e)
        {
            insertautos();
            UpdateModel();
            MessageBox.Show("保存成功!");
        }

        private void com_sslb_SelectedIndexChanged(object sender, EventArgs e)
        {
            checkfujian(true);
        }

        private void text_hphm_KeyPress(object sender, KeyPressEventArgs e)
        {
             if((int)e.KeyChar>=97 && (int)e.KeyChar<=122) 
             {
                 e.KeyChar = (char)((int)e.KeyChar - 32);
             }
        }

        private void skinPictureBox1_MouseHover(object sender, EventArgs e)
        {

            ToolTip ttpSettings = new ToolTip();
            ttpSettings.InitialDelay = 200;
            ttpSettings.AutoPopDelay = 10 * 1000;
            ttpSettings.ReshowDelay = 200;
            ttpSettings.ShowAlways = true;
            ttpSettings.IsBalloon = true;

            string tipOverwrite = string.Format("F1：车辆外观检验 \r\nC1：底盘检验\r\nB1：一轴制动\r\nB2：二轴制动\r\nB0：驻车制动\r\nS1：车速表\r\nA1：侧滑\r\n");
            ttpSettings.SetToolTip(skinPictureBox1, tipOverwrite); 
        }

        private void text_cxdm_TextChanged(object sender, EventArgs e)
        {
            getcpxh();
        }

        private void text_clpp_TextChanged(object sender, EventArgs e)
        {
            getcpxh();
        }

        public void getcpxh()
        {
            if (string.IsNullOrEmpty(cxbclpp.Text) || string.IsNullOrEmpty(cxbcxdm.Text))
            {
                return;
            }
            Query mquery = new Query();
            string sql;
            sql = string.Format(@"Select * from VehModel Where AUT_BRAND='{0}' and MODEL_ID='{1}'", cxbclpp.Text, cxbcxdm.Text);
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                text_dengzhi.Text = dt.Rows[0]["AUT_LAMP"].ToString().Trim();
                text_rlzl.Text = dt.Rows[0]["AUT_FUEL"].ToString().Trim();
                text_zzl.Text = dt.Rows[0]["AUT_MASSTT"].ToString().Trim();
                text_zbzl.Text = dt.Rows[0]["AUT_MASSRD"].ToString().Trim();
                text_hzzl.Text = "0";
                text_zws.Text = dt.Rows[0]["AUT_MASSLD"].ToString().Trim();
                text_CLLX.Text = dt.Rows[0]["VCLASS_ID"].ToString().Trim();
                text_dlxj.Text = "非独立悬架";

                text_gl.Text = dt.Rows[0]["AUT_TORPOW"].ToString().Trim();
                com_qdxs.Text = "后驱";
                text_zzs.Text = "2";
                com_zzzw.Text = "2";
            }
            else
            {
                sql = string.Format(@"Select top 1 * from AUTO Where AT_CLZWPP='{0}' and AT_CLXH='{1}' order by AT_ID desc", cxbclpp.Text, cxbcxdm.Text);
                dt = mquery.GetTable(sql);
                if (dt.Rows.Count > 0)
                {
                    text_dengzhi.Text = dt.Rows[0]["AT_LAMP"].ToString().Trim();
                    text_rlzl.Text = dt.Rows[0]["AT_RYZL"].ToString().Trim();
                    text_zzl.Text = dt.Rows[0]["AT_ZZL"].ToString().Trim();
                    text_zbzl.Text = dt.Rows[0]["AT_ZBZL"].ToString().Trim();
                    text_hzzl.Text = dt.Rows[0]["AT_HDZZL"].ToString().Trim();
                    text_zws.Text = dt.Rows[0]["AT_HDZK"].ToString().Trim();

                    text_dlxj.Text = dt.Rows[0]["AT_SUTYPE"].ToString().Trim();

                    text_gl.Text = dt.Rows[0]["AT_GL"].ToString().Trim();
                    com_qdxs.Text = dt.Rows[0]["AT_QDFS"].ToString().Trim();
                    text_zzs.Text = dt.Rows[0]["AT_ZS"].ToString().Trim();
                    com_zzzw.Text = dt.Rows[0]["AT_ZCZW"].ToString().Trim();
                }
            }
        }

        public void getcxdm()
        {
            Query mquery = new Query();
            string sql;
            sql = string.Format(@"Select distinct MODEL_ID From VehModel where AUT_BRAND='{0}'", cxbclpp.Text);
            DataTable dt = mquery.GetTable(sql);
            cxbcxdm.Items.Clear();
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    cxbcxdm.Items.Add(dt.Rows[i]["MODEL_ID"].ToString().Trim());
                }
            }
        }

        public void getclcp()
        {
            Query mquery = new Query();
            string sql;
            sql = string.Format(@"Select distinct AUT_BRAND From VehModel");
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    cxbclpp.Items.Add(dt.Rows[i]["AUT_BRAND"].ToString().Trim());
                }
            }
        }

        private void text_dengzhi_MouseClick(object sender, MouseEventArgs e)
        {
            getcpxh();
        }

        private void anjianlogin_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SendKeys.Send("{TAB}");
            }
        }

        private void che_DZSS_CheckedChanged(object sender, EventArgs e)
        {
            checkfujian(true);
        }

        private void text_hphm_TextChanged(object sender, EventArgs e)
        {
            text_clsbm.Text = text_hphm.Text;
        }

        private void cxbclpp_SelectedIndexChanged(object sender, EventArgs e)
        {
            getcxdm();
        }

        private void UpdateModel()
        {
            Query mquery = new Query();
            string sql = string.Format(@"Select * from VehModel Where AUT_BRAND='{0}' and MODEL_ID='{1}'", cxbclpp.Text, cxbcxdm.Text);
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count == 0)
            {
                sql = string.Format("Insert Into VehModel(AUT_BRAND,MODEL_ID,AUT_FUEL,AUT_MASSTT,AUT_MASSRD,AUT_MASSLD,VCLASS_ID,AUT_TORPOW,AUT_LAMP) Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')", cxbclpp.Text, cxbcxdm.Text, text_rlzl.Text, text_zzl.Text, text_zbzl.Text, text_zws.Text, text_CLLX.Text, text_gl.Text, text_dengzhi.Text);
                mquery.InsertDB(sql);
            }
        }
    }
}
